/* 
 * File:   widget_curve.cpp
 * Author: dima
 * 
 * Created on 12 Январь 2015 г., 15:24
 */

#include "widget_curve.h"
#include <qwt_plot_grid.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>

widget_curve::widget_curve(QWidget *widget) : QwtPlot(widget)
{
    init_window();
}

widget_curve::widget_curve(const QwtText &title, QWidget *widget) : QwtPlot(title, widget)
{
    init_window();
}

widget_curve::~widget_curve()
{
    delete X;
    delete Y;
    delete curve;
    delete grid;

}
void widget_curve::set_title(QString set_title)// set title for curve
{
    curve->setTitle(set_title);
}
void widget_curve::set_data()//Set the data for the curve
{
    curve->setSamples(*X, *Y);
    curve->attach(this);
    this->replot();
}

void widget_curve::add_value(double x, double y)//Add interval  for the histogram
{
    X->append(x);
    Y->append(y);
}

void widget_curve::init_window()//initialization window
{
    setCanvasBackground(Qt::white); // background color
    // Enable grid
    grid = new QwtPlotGrid();
    grid->setMajorPen(QPen(Qt::gray, 2)); // line color and thickness
    grid->attach(this);

    // Create the curve
    curve = new QwtPlotCurve();
    curve->setRenderHint(QwtPlotItem::RenderAntialiased);
    curve->setPen(QPen(Qt::blue));
    QwtSymbol *symbol=new QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::yellow), QPen(Qt::red, 2), QSize(8, 8)); // markers curve
    curve->setSymbol(symbol);

    X = new QVector<double>;
    Y = new QVector<double>;
}